<?php if(isset($this->all_items)){?>

	<script type="text/javascript">
		function showDescription(obj){
			$$('.ja-job-description').setStyle('display', 'block');
			$E('#ja-control-description .hide').setStyle('display', '');
			$E('#ja-control-description .show').setStyle('display', 'none');
		}
		function hideDescription(){
			$$('.ja-job-description').setStyle('display', 'none');
			$E('#ja-control-description .hide').setStyle('display', 'none');
			$E('#ja-control-description .show').setStyle('display', '');
		}
	</script>

	<?php 
	
	global $jbconfig;
	
	$thisLink = str_replace(JPATH_ROOT, JURI::root(), dirname(__FILE__));
	$thisLink = str_replace(DS, "/", $thisLink)."/style.css";
	if( ! isset ($formName) )
		$formName = "adminForm";
	?>
	<link rel="stylesheet" href="<?php echo $thisLink;?>" type="text/css" />
	
	<?php $filter_order = JRequest::getVar('filter_order', $jbconfig['posts']->get('filter_order', 'a.id')); ?>
	<?php $filter_order_dir = JRequest::getVar('filter_order_Dir', $jbconfig['posts']->get('filter_order_Dir', 'desc'));?>
	
	<!-- BOX ACTION TOP -->
	<?php if (count($this->all_items)>0) {?>
	<div id="ja-box-action-top">
		<?php if(!isset($module)){?>
	    <div class="ja-sortlist clearfix">
			<span><label for="filter_order_2"><?php echo JText::_('Sort By')?>:</label></span>
			<?php if(substr(trim($filter_order), 0, 2)=='a.') $filter_order = substr(trim($filter_order), 2)?>
			<select class="sortby" onchange="$('filter_order').value=this.value; doSearch('<?php echo $this->layout?>');" name="filter_order_2" id="filter_order_2">
			 	<option value="a.is_hotjob" <?php if($filter_order=='is_hotjob'){?>selected="selected"<?php }?>><?php echo JText::_('Featured Job')?></option>
				<option value="a.effected_date" <?php if($filter_order=='effected_date'){?>selected="selected"<?php }?>><?php echo JText::_('Date')?></option>
				<option value="a.id" <?php if($filter_order=='id'){?>selected="selected"<?php }?>><?php echo JText::_('Job ID')?></option>
				<option value="a.location_id" <?php if($filter_order=='location_id'){?>selected="selected"<?php }?>><?php echo JText::_('Location')?></option>
				<option value="a.title" <?php if($filter_order=='title'){?>selected="selected"<?php }?>><?php echo JText::_('Job Title')?></option>
				<option value="profi.company" <?php if($filter_order=='profi.company'){?>selected="selected"<?php }?>><?php echo JText::_('Company Name')?></option>
			</select>
			
			<select class="sortby" onchange="$('filter_order_Dir').value=this.value; doSearch('<?php echo $this->layout?>');" name="filter_order_Dir_2" id="filter_order_Dir_2">
				<option value="asc" <?php if($filter_order_dir=='asc'){?>selected="selected"<?php }?>><?php echo JText::_('ASC')?></option>
				<option value="desc" <?php if($filter_order_dir=='desc'){?>selected="selected"<?php }?>><?php echo JText::_('DESC')?></option>
			</select>
		</div>
		<?php } if( $jbconfig['posts']->get('posts_show_description', 1) ){ ?>
		
		<div id="ja-control-description">
			<a class="button show" href="javascript:showDescription()" style="display: none">
				<span style="vertical-align: top ! important;"><?php echo JText::_('Show Job Descriptions')?></span>
			</a>
			<a class="button hide" href="javascript:hideDescription()">
				<span style="vertical-align: top ! important;"><?php echo JText::_('Hide Job Descriptions')?></span>
			</a>			
		</div>	
		<?php  } ?>
	</div>
	<?php  } 
		else 
		{
			if (JRequest::getVar('layout')=='job_list_via_profiles')
			echo "<span>".JText::_("Don't have any jobs")."</span>";
		}
	?>
	
	<!-- BOX ACTION TOP -->
	
	<!-- JA JOBLIST -->
	<div id="ja-joblist">		
		<ol id="ja-searchjoblist">
			
			<?php
		  	$items = $this->all_items;
		  	$k = 0;
		  	$orderNo = 0;
		  	$currentTable = '';
		  	$max_length = $jbconfig['posts']->get('posts_description_chars')? $jbconfig['posts']->get('posts_description_chars'):150;
		  	
			$field_salary = null;
			if(isset($this->allFields)){
			  	for($ii = 0, $nn = count($this->allFields); $ii < $nn; $ii++ ){
			  		$field = $this->allFields[$ii];
	                $field_name = $field->field_name;
	                if($field_name=='salary_range'){
	                	$field_salary = $field;
	                	break;
	                }               
			  	}
			}
		  	
		  	for($i = 0, $n = count($this->all_items); $i < $n; $i++, $orderNo++)
		  	if (isset($items[$i]->id))
		  	{
		   		$item = $items[$i];
		   				   		
		   		JFilterOutput::objectHTMLSafe( $item, ENT_QUOTES, 'effected_date' );
		   		
		   		$currency = isset($item->currency)?$item->currency:$jbconfig['currency']->get('currency', '$');
		   		
		   		$temp_user = JFactory::getUser($item->user_id_tmp);
	    		$temp_user->username = str_replace('.','()',$temp_user->username);
		   		$class = '';		   		
		   		if($item->is_hotjob==1) $class = "premiumjob";
  	
				if(is_array($item->cat_id_tmp)) $cats = implode(',', $item->cat_id_tmp);
		   		else $cats = $item->cat_id_tmp;
				$cat_names = getCategories($cats);
				$cats = explode(',',$cat_names);


				if(is_array($item->location_id_tmp)) $locations = implode(',', $item->location_id_tmp);
		   		else $locations = $item->location_id_tmp;
		   		$location_names = getLocation($locations);
		   		$locations = explode(',',$location_names);
		   		?>   		
		   		<?php 
				//Get Logo size
				if (!$item->logo)
				{
					$item->logo = JURI::base () . 'components/com_jajobboard/images/no-image.gif';
				}else $item->logo = JURI::root().$item->logo;
				
				$item->logo = str_replace( JURI::base(), "",  $item->logo);
				
				$logo_size = jaGetImageSize($item->logo);
				$logo_width = $logo_size['width'];
				$logo_height = $logo_size['height'];
				if ( strpos( $item->logo, JURI::base() ) === false )
							$item->logo = JURI::base().$item->logo;
				
				?> 	         
		   		
				<li id="li_<?php echo $item->id; ?>" class="<?php echo $class?>  row<?php echo ($i%2); ?> <?php if ($i+1==$n): echo 'last'; endif;?>" onmouseover="$(this).addClass('hover')" onmouseout="$(this).removeClass('hover')">
					<div class="ja-job-details">
						
						<!-- JOB TITLE -->
						<h3 class="ja-job-title">
							<?php $alias = JFilterOutput::stringURLSafe(trim($item->title));?>
							<a href="<?php echo JRoute::_( 'index.php?option='. JBCOMNAME .'&view=jajobs&layout=jaview&cid[]='.$item->id.'&alias='.$alias.'&Itemid='.$this->Itemid); ?>"  class="<?php echo $class;?>">
								<?php echo $item->title; ?>
							</a>	
							 <?php if($item->is_hotjob) { ?>
								<img width="75" height="15" alt="Featured Job" src="components/com_jajobboard/views/jajobs/tmpl/themes/summary/images/featured-job.png"/>		
							 <?php }?>				
							
		         		</h3>
		         		<!-- //JOB TITLE -->
						
						<div class="col-left">
							
							<div class="ja-job-category clearfix">
		          				<label><?php echo JText::_('Location')?></label>				
								<?php foreach ($locations as $location) { ?>
		            				<a href="<?php echo JRoute::_('index.php?option=com_jajobboard&view=jajobs&layout=filter_job_list&location_id='.$location.'&Itemid='.$this->Itemid)?>" title="<?php echo $location?>"><?php echo $location?></a> 
		            			<?php } ?>	
							</div>
							<div class="ja-job-category clearfix">
								<?php if($cats && $jbconfig['posts']->get('posts_show_job_type', 1) ) { ?>
			            			<label><?php echo JText::_('Category')?></label>
									<?php foreach ($cats as $cat) { ?>
			            				<a href="<?php echo JRoute::_('index.php?option=com_jajobboard&view=jajobs&layout=filter_job_list&cat_id='.$cat.'&Itemid='.$this->Itemid)?>" title="<?php echo $cat?>"><?php echo $cat?></a> 
			            			<?php } ?>				            
			            		<?php } ?>
		          			</div>
		          			<div class="ja-job-category clearfix">
		          				<label><?php echo JText::_('Salary')?></label>				
								<!-- SALARY -->
				           		<?php if(isset($item->salary_range)){?>
				           		<span class="ja-job-salary">
				           			<?php if(isset($item->salary_min) && isset($item->salary_max) && ($item->salary_min || $item->salary_max)){?>                   					
				           				<?php echo $currency.$item->salary_min?> - <?php echo $currency.$item->salary_max?>
				           			<?php }elseif($field_salary){
				           					echo rendfield($item, $field_salary,false,true,true);            				
				           			} ?>	    
											</span>               			
				           		<?php }?>	
				           	<!-- //SALARY -->
							</div>
							<?php if($jbconfig['posts']->get('posts_show_posted_by', 1)){ ?>
							<div class="ja-job-category clearfix">
		            			<label><?php echo JText::_('Company')?></label>
								<span class="ja-companyname">
						            <a href="<?php echo JRoute::_( 'index.php?option='. JBCOMNAME .'&view=japrofiles&layout=jaview&cid[]='.$temp_user->username."&profile_id=".$temp_user->username); ?>"  class="<?php echo $class;?>">
						            	<?php echo $item->company?>
						            </a>
					            </span>				            
		          			</div>
		          			<?php }?>
							
						</div>
						
						<div class="col-right">
							<?php if($jbconfig['posts']->get('postsshow_days_elapsed', 1) ) { ?>
							<div class="ja-job-category dateAdded">
								<label><?php echo JText::_('Date')?></label>
								<span class="datetime"><?php echo $item->effected_date?></span>
		          			</div>
		          			<?php } ?>
		          			
		          			<?php if($jbconfig['posts']->get('posts_show_posted_by', 1)){ ?>
		          			<div class="ja-job-category logo">
			          			<a href="<?php echo JRoute::_( 'index.php?option='. JBCOMNAME .'&view=japrofiles&layout=jaview&cid[]='.$temp_user->username."&profile_id=".$temp_user->username); ?>"  class="<?php echo $class;?>">
					            	<img src="<?php echo $item->logo?>" alt="<?php echo $item->company?>" class="logo" align="left" width="<?php echo $logo_width?>" height="<?php echo $logo_height?>"/>
					            </a>
					        </div>
					        <?php }?>
						</div>
						
						<div class="ja-job-description clearfix">
							<?php 
								if( $jbconfig['posts']->get('posts_show_description', 1) ){							
									$item->job_detail = htmlspecialchars_decode($item->job_detail);
									echo SmartTrim::trim($item->job_detail,0,$max_length);
								} 
							?>
						</div>
						<div style="clear:both">
        				<?php if (getCurrentUserType() == JBEMPLOYER_USER  && JRequest::getVar("layout") == "myjobs") { 
							$numApplications = JobBoardModelJAJobs::getNumApplications($item->id);
							if( $numApplications > 0 ){
							?>
						    <br/><strong style="font-size:120%"><?php echo JText::_("Applications");?></strong>: <a target="_blank" href="<?php echo JRoute::_('index.php?option=com_jajobboard&view=jaapplications&layout=jaempllist&job_id='.$item->id);?>"><?php echo $numApplications;?></a>
						<?php } else { 
							?>
							<br/><strong style="font-size:120%"><?php echo JText::_("Applications");?></strong>: <?php echo $numApplications;?>
							<?php				
						} } ?>
        				<?php if ( JRequest::getVar("zipcode_distance", "") != "" ) { ?>
						    <br/><strong style="font-size:120%"><?php echo JText::_("Distance from zipcode: ".JRequest::getVar("zipcode_from", "")." is: " );?></strong> <?php echo $item->zipcode_distance ?> (miles)
						<?php } ?>
        				</div>
					</div>  					
        		</li>
		            
		  <?php } ?>
	 	</ol>
	 </div>
	 <!-- //JA JOBLIST -->
<?php if (count($this->all_items)>0) {?>	 	 
	<?php if(isset($this->pagination)) {?>
		<div class="jobs-pagination clearfix">
			<div class="limit">
				<label for="limit"><?php echo JText::_("Display num")?></label>
				<?php echo $this->getListLimit(JRequest::getInt('limit', $jbconfig['posts']->get('display_num'))); ?>
			</div>
			
			<?php echo $this->pagination->getPagesLinks(); ?>
		</div>
	<?php } ?>
	
<?php 
		}  
	}
		
?>